package wang.aweb.childcar.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import wang.aweb.childcar.model.dao.SystemMapper;
import wang.aweb.childcar.model.pojo.System;
import wang.aweb.childcar.service.SystemInfoService;

import java.util.HashMap;
import java.util.Map;

@Service
public class SystemInfoServiceImpl implements SystemInfoService {
    @Autowired
    private SystemMapper systemMapper;
    @Override
    public Map getInfo(){
        System info=systemMapper.getInfo(1);
        Map sysMap=this.systemToSystemVO(info);
        return sysMap;
    }
    public Map systemToSystemVO(System info){
        Map sysMap=new HashMap();
        if(info.getDonateEnable()==1){
            sysMap.put("donate_enable",true);
        }else{
            sysMap.put("donate_enable",false);
        }

        sysMap.put("donate_money",info.getDonateMoney()/100);
        return sysMap;
    }
    public void update(Boolean donateEnable, Integer donateMoney) {
        System system=new System();
        system.setId(1);
        if(donateEnable==true){
            system.setDonateEnable(1);
        }else{
            system.setDonateEnable(0);
        }
        system.setDonateMoney(donateMoney*100);
        systemMapper.updateByPrimaryKey(system);
    }
}
